<?php
	//this is smd generator from public classes in directory ../classes
	require_once('../classes/DatabaseClass.php');
	require_once('../classes/XSSClass.php');
	
	if (isset($_GET['class'])) {
		$db = DBhandler::getInst();
		$xss = new XSSClass();
		
		$className = $xss->removeXSS($db->rmInject($_GET['class']));
		$smdClassName = $className;
		$className .= "Class";
		require_once("../rpcClasses/".$className.".php");
		
		$refClass = new ReflectionClass($className);
		
		$smd = new stdClass();
		$smd->SMDVersion = "1";
		$smd->serviceType = "JSON-RPC";
		$smd->serviceURL = "../server/index.php?srv=$smdClassName";
		$smd->objectName = $className;
		$smd->methods = array();
		
		foreach($refClass->getMethods() as $method) {
			if (!$method->isPublic()) {
				continue;
			}
			
			$methodDef = new stdClass();
			$methodDef->name = $method->getName();
			$methodDef->parameters = array();
			$smd->methods[] = $methodDef;
			foreach ($method->getParameters() as $parameter) {
				$paramDef = new stdClass();
				$paramDef->name = $parameter->getName();
				$methodDef->parameters[] = $paramDef;
			}
		}
		echo json_encode($smd);
	}
?>